using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.Content;

namespace TimeWar
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class TeamSelection : Screen
    {
        private List<Companion> companions = null;
        private Cultures culture;
        private Game gameObj;
        private GameCursor cursor;

        public TeamSelection(Game game, Cultures selectedCulture)
            : base(game)
        {
            // TODO: Construct any child components here
            companions = new List<Companion>();
            culture = selectedCulture;
            gameObj = game;
            Initialize();
        }

        public Cultures Culture
        {
            get
            {
                return culture;
            }
        }
        

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public void Initialize()
        {
            // TODO: Add your initialization code here
            if (culture == Cultures.TimeLords)
            {
                Companion friend = new Companion("Captain Jack Harkness", "Content\\Textures\\CaptainJackIcon", "Content\\Textures\\CaptainJackFull");
                companions.Add(friend);
                friend = new Companion("Optimus Prime", "Content\\Textures\\OptimusPrimeIcon", "Content\\Textures\\OptimusPrimeFull");
                companions.Add(friend);
                friend = new Companion("Chuck", "Content\\Textures\\ChuckIcon", "Content\\Textures\\ChuckFull");
                companions.Add(friend);
                friend = new Companion("Apollo", "Content\\Textures\\LeeAdamaIcon", "Content\\Textures\\LeeAdamaFull");
                companions.Add(friend);



            }

            cursor = new GameCursor(game, SpriteBatch);
            cursor.Initialize();

        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override GameState Update(TimeSpan time, TimeSpan elapsedTime)
        {
            if (XInputHelper.GamePads[PlayerIndex.One].XPressed)
            {
                return GameState.PlayDemo;
            }


            return GameState.TeamSelection;
        }

        public override void Render()
        {
            Rectangle destRect = new Rectangle(0, 0, 200, 200);
            Vector2 originVector = new Vector2(0, 0);

            IGraphicsDeviceService graphicsService = (IGraphicsDeviceService)GameInstance.Services.GetService(typeof(IGraphicsDeviceService));

            GraphicsDevice device = graphicsService.GraphicsDevice;

            //Sprites will always be at the back.
            device.RenderState.DepthBufferWriteEnable = false;

            SpriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.BackToFront, SaveStateMode.None);
            //SpriteFont testFont = TimeWarGame.ContentManager.Load<SpriteFont>("Content\\Fonts\\CourierNew");
            //SpriteBatch.DrawString(testFont, "Hello world", new Vector2(0, 0), Color.Red);

            foreach (Companion obj in companions)
            {
                SpriteBatch.Draw(obj.Icon, destRect, obj.OriginalIcon, Color.White, 0, originVector, SpriteEffects.None, 1);
                //obj.Position = originVector;
                //SpriteBatch.Draw(obj.Icon, obj.Position, null, Color.White, 0, new Vector2(0, 0), 0, SpriteEffects.None, 1);
                //SpriteBatch.Draw(obj.Icon, obj.Position, Color.White);
                destRect.X = destRect.X + destRect.Width;
                //originVector.X = originVector.X + obj.Icon.Width;
            }

            cursor.Draw();

            SpriteBatch.End();


            base.Render();


        }
    }
}